const mongoose = require('mongoose');
const AdminSchema = mongoose.Schema({
   username: {
      type: String,
      validate: {
         validator(val) {
            return /^[a-zA-Z0-9_]{3,15}$/.test(val)
         },
         tip: "账号错误！字母或数字开头长度至少3个！",
         message: "账号错误！字母或数字开头长度至少3个！"
      }
   },
   password: {
      type: String,
      validate: {
         validator(val) {
            return /^[a-zA-Z0-9_]{3,15}$/.test(val)
         },
         tip: "密码错误！字母或数字开头长度至少3个！",
         message: "密码错误！字母或数字开头长度至少3个！"
      }
   },
   uImage: {
      type: String,
      // default: 'http://120.78.9.102:8010/uploads/filename-1647772850256576.webp'
      default: 'http://127.0.0.1:3000/uploads/filename-16476159252634343.webp'
   },
   role: {
      type: Number,
      enums: [1, 2], //1 管理员  2 普通用户
      default: 2
   },
   status: {
      type: Number,
      enums: [0, 1], //0 不允许登录  1 允许登录
      default: 0
   },
   datetime: { //记录发表时间
      type: Number, //存储一个数字时间戳 默认是当前时间
      default: Date.now()
   }

});

const AdminModel = mongoose.model('admin', AdminSchema);
module.exports = AdminModel